<?php
/**
 *
 * Author:苏光盼
 * web:https://api.jifen.suanzisu.com
 * date:2019/12/27 下午12:48
 * class:AdminGroup.php
 * Project:通用APP后台管理系统
 *
 */

namespace App\Model;
use EasySwoole\Http\Message\Status;
use EasySwoole\ORM\AbstractModel;
use EasySwoole\ORM\Exception\Exception;

class AdmGroup extends AbstractModel
{
    protected $tableName = 'adm_group';
    protected $autoTimeStamp = false;


    /**
     * @param AdmGroup $mode
     * @param $deleteId
     * 删除之前的事件
     *
     * @return bool
     * @throws Exception
     * @throws \Throwable
     */
    protected static function onBeforeDelete(self $mode){
            $has = Adm::create()->where('group_id',$mode->id)->count();
            if( $has > 0 ){
                throw new Exception('不能删除！此用户组还有人在使用！',Status::CODE_FORBIDDEN);
            }
    }
}